/*
 * SampleCollector.cpp
 *
 *  Created on: May 16, 2010
 *      Author: Soheil Damangir
 */

# include <string>

# include "printfstring.h"
# include "camera_reader.h"
# include "image_processor.h"
# include "log.h"
# include "time_tools.h"

# include "SampleCollector.h"

using namespace std;
using namespace kthrobot;
namespace Group5 {
string SampleCollector::PREF;
SampleCollector::SampleCollector(const char* _pref) :
  image_no_(0)
{
  strcpy(pref, _pref);
  cam_reader = new CameraReader("130.237.226.228", &jpeg_buffers, &jpeg_queue);
  processor = new ImageProcessor(&jpeg_queue, this);
  Log::Write("Sample Collector is set up successfully.");
}

void SampleCollector::ProcessImage(Image *image) {
  string file_name = PrintFString("%s_%03d.ppm", pref, image_no_);
  image->SavePPM(file_name);
  Log::Write("We saved this image: %s", file_name.c_str());
  ++image_no_;
  TimeTools::WaitMS(100);
}

void SampleCollector::Collect() {
  cam_reader->Start();
  processor->Start();
  Log::Write("Collecting images");
}
void SampleCollector::Stop() {
  cam_reader->SignalStop();
  processor->SignalStop();
  Log::Write("Stopping image collector.");
}
SampleCollector::~SampleCollector() {
  Log::Write("Sample Collector destructed successfully**.");
  delete cam_reader;
  delete processor;
  Log::Write("Sample Collector destructed successfully.");
}
}
